home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / tftp / cmd.c next >
C/C++ Source or Header  |  1989-12-17  |  3KB  |  191 lines

  1. /*
  2.  * Command processing functions, one per command.
  3.  * (Only the client side processes user commands.)
  4.  * In alphabetical order.
  5.  */
  6.  
  7. #include    "cmd.h"
  8.  
  9. /*
  10.  * ascii
  11.  *
  12.  *    Equivalent to "mode ascii".
  13.  */
  14.  
  15. cmd_ascii()
  16. {
  17.     modetype = MODE_ASCII;
  18. }
  19.  
  20. /*
  21.  * binary
  22.  *
  23.  *    Equivalent to "mode binary".
  24.  */
  25.  
  26. cmd_binary()
  27. {
  28.     modetype = MODE_BINARY;
  29. }
  30.  
  31. /*
  32.  * connect <hostname> [ <port> ]
  33.  *
  34.  *    Set the hostname and optional port number for future transfers.
  35.  *    The port is the well-known port number of the tftp server on
  36.  *    the other system.  Normally this will default to the value
  37.  *    specified in /etc/services (69).
  38.  */
  39.  
  40. cmd_connect()
  41. {
  42.     register int    val;
  43.  
  44.     if (gettoken(hostname) == NULL)
  45.         err_cmd("missing hostname");
  46.  
  47.     if (gettoken(temptoken) == NULL)
  48.         return;
  49.     val = atoi(temptoken);
  50.     if (val < 0)
  51.         err_cmd("invalid port number");
  52.     port = val;
  53. }
  54.  
  55. /*
  56.  * exit
  57.  */
  58.  
  59. cmd_exit()
  60. {
  61.     exit(0);
  62. }
  63.  
  64. /*
  65.  * get <remotefilename> <localfilename>
  66.  *
  67.  *    Note that the <remotefilename> may be of the form <host>:<filename>
  68.  *    to specify the host also.
  69.  */
  70.  
  71. cmd_get()
  72. {
  73.     char    remfname[MAXFILENAME], locfname[MAXFILENAME];
  74.     char    *index();
  75.  
  76.     if (gettoken(remfname) == NULL)
  77.         err_cmd("the remote filename must be specified");
  78.     if (gettoken(locfname) == NULL)
  79.         err_cmd("the local filename must be specified");
  80.  
  81.     if (index(locfname, ':') != NULL)
  82.         err_cmd("can't have 'host:' in local filename");
  83.  
  84.     striphost(remfname, hostname);    /* check for "host:" and process */
  85.     if (hostname[0] == 0)
  86.         err_cmd("no host has been specified");
  87.  
  88.     do_get(remfname, locfname);
  89. }
  90.  
  91. /*
  92.  * help
  93.  */
  94.  
  95. cmd_help()
  96. {
  97.     register int    i;
  98.  
  99.     for (i = 0; i < ncmds; i++) {
  100.         printf("  %s\n", commands[i].cmd_name);
  101.     }
  102. }
  103.  
  104. /*
  105.  * mode ascii
  106.  * mode binary
  107.  *
  108.  *    Set the mode for file transfers.
  109.  */
  110.  
  111. cmd_mode()
  112. {
  113.     if (gettoken(temptoken) == NULL) {
  114.         err_cmd("a mode type must be specified");
  115.     } else {
  116.         if (strcmp(temptoken, "ascii") == 0)
  117.             modetype = MODE_ASCII;
  118.         else if (strcmp(temptoken, "binary") == 0)
  119.             modetype = MODE_BINARY;
  120.         else
  121.             err_cmd("mode must be 'ascii' or 'binary'");
  122.     }
  123. }
  124.  
  125. /*
  126.  * put <localfilename> <remotefilename>
  127.  *
  128.  *    Note that the <remotefilename> may be of the form <host>:<filename>
  129.  *    to specify the host also.
  130.  */
  131.  
  132. cmd_put()
  133. {
  134.     char    remfname[MAXFILENAME], locfname[MAXFILENAME];
  135.  
  136.     if (gettoken(locfname) == NULL)
  137.         err_cmd("the local filename must be specified");
  138.     if (gettoken(remfname) == NULL)
  139.         err_cmd("the remote filename must be specified");
  140.  
  141.     if (index(locfname, ':') != NULL)
  142.         err_cmd("can't have 'host:' in local filename");
  143.  
  144.     striphost(remfname, hostname);    /* check for "host:" and process */
  145.     if (hostname[0] == 0)
  146.         err_cmd("no host has been specified");
  147.  
  148.     do_put(remfname, locfname);
  149. }
  150.  
  151. /*
  152.  * Show current status.
  153.  */
  154.  
  155. cmd_status()
  156. {
  157.     if (connected)
  158.         printf("Connected\n");
  159.     else
  160.         printf("Not connected\n");
  161.  
  162.     printf("mode = ");
  163.     switch (modetype) {
  164.     case MODE_ASCII:    printf("netascii");        break;
  165.     case MODE_BINARY:    printf("octet (binary)");    break;
  166.     default:
  167.         err_dump("unknown modetype");
  168.     }
  169.  
  170.     printf(", verbose = %s", verboseflag ? "on" : "off");
  171.     printf(", trace = %s\n", traceflag ? "on" : "off");
  172. }
  173.  
  174. /*
  175.  * Toggle debug mode.
  176.  */
  177.  
  178. cmd_trace()
  179. {
  180.     traceflag = !traceflag;
  181. }
  182.  
  183. /*
  184.  * Toggle verbose mode.
  185.  */
  186.  
  187. cmd_verbose()
  188. {
  189.     verboseflag = !verboseflag;
  190. }
  191.